﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using widgetLoader.Properties;
using wdwp.Desktop.widgetLib.Utils;

namespace wdwp.Desktop.Loader
{
    /// <summary>
    /// 위젯 세팅정보
    /// </summary>
    public partial class WidgetSettingsForm : Form
    {
        Form m_ParentForm;


        public WidgetSettingsForm(Form ParentForm)
        {
            InitializeComponent();

            m_ParentForm = ParentForm;
        }
        

        private void btn_startListen_Click(object sender, EventArgs e)
        {
            Process myProc = Process.GetCurrentProcess();

            listLog.Items.Add("myProc ID:" + myProc.Id + " Name :" + myProc.ProcessName);
            listLog.Items.Add("Main window handle: " + myProc.MainWindowHandle.ToString("X2"));

            //myProc.OutputDataReceived += new DataReceivedEventHandler(StdOut_OutputDataRecieved);
        }

        private void widgetSettings_Load(object sender, EventArgs e)
        {
            trackBar_Opacity.Value = (int)Settings.Default.Opacity; //(int)(Settings.Default.Opacity * 10);

            trackBar_Opacity.ValueChanged += new EventHandler(trackBar_Opacity_ValueChanged);
            
            listLog.Items.Add(Settings.Default.Uri.ToString());
            listLog.Items.Add(Settings.Default.Width.ToString());
            listLog.Items.Add(Settings.Default.Height.ToString());
            listLog.Items.Add(Settings.Default.Name.ToString());
        }

        void trackBar_Opacity_ValueChanged(object sender, EventArgs e)
        {
            TrackBar aSender = sender as TrackBar;

            //Settings.Default.Opacity = (float)aSender.Value / 10;            
        }


        public void _Log(string Msg)
        {
            listLog.Items.Insert(0,Msg);
        }

                
        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
     

        private void chkAlwaysOnTop_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox aSender = sender as CheckBox;

            if (aSender.Checked)
            {
                NativeWin32.SetWindowPos(m_ParentForm.Handle, NativeWin32.HWND_TOPMOST, 0, 0, 0, 0, NativeWin32.SWP_NOMOVE | NativeWin32.SWP_NOSIZE); 
            }
            else
            {
                NativeWin32.SetWindowPos(m_ParentForm.Handle, NativeWin32.HWND_TOP, 0, 0, 0, 0, NativeWin32.SWP_NOMOVE | NativeWin32.SWP_NOSIZE); 
            }

            Settings.Default.AlwaysOnTop = aSender.Checked;
        }

     
    }
}
